package com.util.cdb.enums;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.StringUtils;

/**
 * @description: mysql操作及SQL
 * @author: fengfazheng
 * @create: 2021-12-26 21:27
 **/
@Getter
@AllArgsConstructor
public enum MysqlEnum {
    /**
     * mysql操作Sql枚举
     */
    SHOW_DATABASES("1", "SHOW DATABASES"),
    SHOW_TABLES("2", "SHOW TABLES"),
    SELECT_FROM_TABLE("3","SELECT * FROM %s LIMIT %s,%s ")
    ;
    private final String operation;
    private final String operationSql;

    public static String getOperationSql(String operation) {
        if (StringUtils.isEmpty(operation)) {
            throw new UnsupportedOperationException();
        }
        for (MysqlEnum mysqlEnum : values()) {
            if (mysqlEnum.getOperation().equals(operation)) {
                return mysqlEnum.getOperationSql();
            }
        }
        throw new UnsupportedOperationException();
    }
}
